DATAUP-729: job timestamp easy pickings#2950
Conversation
| """ | ||
| A module for managing apps, specs, requirements, and for starting jobs. | ||
| """ | ||
| import datetime |
|
|
||
| class Job(object): | ||
| _job_logs = list() | ||
| class Job: |
There was a problem hiding this comment.
no need for (object) in python 3
| class Job(object): | ||
| _job_logs = list() | ||
| class Job: | ||
| _job_logs = [] |
There was a problem hiding this comment.
from the flake8-comprehensions plugin (installed locally)
| """ | ||
| attr = dict( | ||
| app_id=lambda: self._acc_state.get("job_input", {}).get( | ||
| attr = { |
There was a problem hiding this comment.
flake8-comprehensions again
| # Check if there would be no change in updating | ||
| # i.e., if state <= self._acc_state | ||
| if self._acc_state is not None: | ||
| if {**self._acc_state, **state} == self._acc_state: | ||
| return |
There was a problem hiding this comment.
prep for upcoming timestamps work
|
This pull request introduces 2 alerts when merging 3dc225d into 213fd59 - view on LGTM.com new alerts:
|
|
|
||
| @property | ||
| def ts(self): | ||
| """This param is completely optional""" |
There was a problem hiding this comment.
@n1mus is going to write a better description for this param in a forthcoming PR 😁
| MESSAGE_TYPE["CANCEL"]: self.cancel_jobs, | ||
| MESSAGE_TYPE["CELL_JOB_STATUS"]: self.get_job_states_by_cell_id, | ||
| MESSAGE_TYPE["INFO"]: self.get_job_info, | ||
| MESSAGE_TYPE["LOGS"]: self.get_job_logs, | ||
| MESSAGE_TYPE["RETRY"]: self.retry_jobs, | ||
| MESSAGE_TYPE["START_UPDATE"]: self._modify_job_updates, | ||
| MESSAGE_TYPE["STATUS"]: self._get_job_states, | ||
| MESSAGE_TYPE["STATUS_ALL"]: self._get_all_job_states, | ||
| MESSAGE_TYPE["STATUS"]: self.get_job_states, | ||
| MESSAGE_TYPE["STATUS_ALL"]: self.get_all_job_states, |
There was a problem hiding this comment.
renamed these methods for clarity and to make a better distinction between top level and internal methods
There was a problem hiding this comment.
Nice! This would always throw me for a loop now that I think of it
| return job_info | ||
|
|
||
| def __get_job_states(self, job_id_list) -> dict: | ||
| def _get_job_states(self, job_id_list: list, ts: int = None) -> dict: |
There was a problem hiding this comment.
note new ts parameter
Codecov Report
@@ Coverage Diff @@
## develop #2950 +/- ##
===========================================
+ Coverage 73.19% 73.25% +0.05%
===========================================
Files 36 36
Lines 3895 3903 +8
===========================================
+ Hits 2851 2859 +8
Misses 1044 1044
Continue to review full report at Codecov.
|
| "return_list": 0, | ||
| } | ||
| ) | ||
| job_states = Job.query_ee2_states(job_ids, init=True) |
There was a problem hiding this comment.
@n1mus has consolidated most of the ee2 queries (apart from the workspace job fetch) to use the query_ee2_state(s) functions.
| self.assertEqual(getattr(jobl, attr), getattr(jobr, attr)) | ||
|
|
||
| def check_job_attrs_custom(self, job, exp_attr={}): | ||
| def check_job_attrs_custom(self, job, exp_attr=None): |
There was a problem hiding this comment.
don't use mutable args as defaults
| import unittest | ||
| from unittest import mock | ||
| import os | ||
| import copy |
There was a problem hiding this comment.
isort got busy on this file!
| ret = str(generator["prefix"]) + ret | ||
| if "suffix" in generator: | ||
| ret = ret + str(generator["suffix"]) | ||
| return ret + str(generator["suffix"]) |
There was a problem hiding this comment.
? No biggie but I thought this was strange
There was a problem hiding this comment.
I've got a flake8 plugin installed locally that warns if there's somewhere where a variable can be returned immediately. This is one such case...
|
|
||
| @property | ||
| def ts(self): | ||
| """This param is completely optional""" |
| MESSAGE_TYPE["CANCEL"]: self.cancel_jobs, | ||
| MESSAGE_TYPE["CELL_JOB_STATUS"]: self.get_job_states_by_cell_id, | ||
| MESSAGE_TYPE["INFO"]: self.get_job_info, | ||
| MESSAGE_TYPE["LOGS"]: self.get_job_logs, | ||
| MESSAGE_TYPE["RETRY"]: self.retry_jobs, | ||
| MESSAGE_TYPE["START_UPDATE"]: self._modify_job_updates, | ||
| MESSAGE_TYPE["STATUS"]: self._get_job_states, | ||
| MESSAGE_TYPE["STATUS_ALL"]: self._get_all_job_states, | ||
| MESSAGE_TYPE["STATUS"]: self.get_job_states, | ||
| MESSAGE_TYPE["STATUS_ALL"]: self.get_all_job_states, |
There was a problem hiding this comment.
Nice! This would always throw me for a loop now that I think of it
| try: | ||
| all_states = self.get_all_job_states(ignore_refresh_flag=True) | ||
| state_list = [s["jobState"] for s in all_states.values()] | ||
| state_list = [copy.deepcopy(s["jobState"]) for s in all_states.values()] |
There was a problem hiding this comment.
Shouldn't need this anymore since we fixed the double- yet leaky-caching, but no biggie
There was a problem hiding this comment.
would you mind fixing it in the next PR?
| self.assertEqual(getattr(jobl, attr), getattr(jobr, attr)) | ||
|
|
||
| def check_job_attrs_custom(self, job, exp_attr={}): | ||
| def check_job_attrs_custom(self, job, exp_attr=None): |
3dc225d to
52e379b
Compare
|
This pull request introduces 2 alerts when merging 52e379b into bcbad86 - view on LGTM.com new alerts:
|
|
Kudos, SonarCloud Quality Gate passed!
|








Description of PR purpose/changes
This is a set of "easy pickings" from @n1mus (or Summit, as autocorrect calls her)'s DATAUP-729-job-ts branch. The original PR was large and complex so this updates and merges it into develop (see the first commit), and then picks out a small-ish set of changes for the first PR. It's expected that there will be (at least) two more PRs to cover the rest of the changes.
I ran
isort, the import sorter, on the altered files.Jira Ticket / Issue
Related Jira ticket: https://kbase-jira.atlassian.net/browse/DATAUP-729
DATAUP-69 Adds a PR template)Testing Instructions
Dev Checklist: